package com.dianping.cat.home.service.transform;

import com.dianping.cat.home.service.IEntity;
import com.dianping.cat.home.service.IVisitor;
import com.dianping.cat.home.service.entity.Domain;
import com.dianping.cat.home.service.entity.ServiceReport;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/* 12 */   private Stack<Object> m_objs = new Stack();

  private ServiceReport m_serviceReport;


  public DefaultMerger() {}

  public DefaultMerger(ServiceReport serviceReport) {
/* 20 */     this.m_serviceReport = serviceReport;
/* 21 */     this.m_objs.push(serviceReport);
  }


/* 25 */   public ServiceReport getServiceReport() { return this.m_serviceReport; }



/* 29 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/* 33 */     this.m_objs.push(to);
/* 34 */     from.accept(this);
/* 35 */     this.m_objs.pop();
  }

  protected void mergeDomain(Domain to, Domain from) {
/* 39 */     to.mergeAttributes(from);
/* 40 */     to.setTotalCount(from.getTotalCount());
/* 41 */     to.setFailureCount(from.getFailureCount());
/* 42 */     to.setFailurePercent(from.getFailurePercent());
/* 43 */     to.setSum(from.getSum());
/* 44 */     to.setAvg(from.getAvg());
/* 45 */     to.setQps(from.getQps());
  }


/* 49 */   protected void mergeServiceReport(ServiceReport to, ServiceReport from) { to.mergeAttributes(from); }



  public void visitDomain(Domain from) {
/* 54 */     Domain to = (Domain)this.m_objs.peek();

/* 56 */     mergeDomain(to, from);
/* 57 */     visitDomainChildren(to, from);
  }


  protected void visitDomainChildren(Domain to, Domain from) {}


  public void visitServiceReport(ServiceReport from) {
/* 65 */     ServiceReport to = (ServiceReport)this.m_objs.peek();

/* 67 */     mergeServiceReport(to, from);
/* 68 */     visitServiceReportChildren(to, from);
  }

  protected void visitServiceReportChildren(ServiceReport to, ServiceReport from) {
/* 72 */     for (Domain source : from.getDomains().values()) {
/* 73 */       Domain target = to.findDomain(source.getId());

/* 75 */       if (target == null) {
/* 76 */         target = new Domain(source.getId());
/* 77 */         to.addDomain(target);
      }

/* 80 */       this.m_objs.push(target);
/* 81 */       source.accept(this);
/* 82 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/service/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */